<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<table class="easyui-datagrid" fit="true" id="userList" title=""
	data-options="singleSelect:false,collapsible:true,pagination:true,url:'/user/list',method:'get',pageSize:30,toolbar:toolbar">
	<thead>
		<tr>
			<th data-options="field:'ck',checkbox:true"></th>
			<th data-options="field:'id',width:60">用户ID</th>
			<th data-options="field:'username',width:130">用户名</th>
			<th data-options="field:'nikename',width:130">用户昵称</th>
			<th data-options="field:'phone',width:200">联系电话</th>
			<th data-options="field:'email',width:200">电子邮件</th>
			<th data-options="field:'created',width:130,align:'center',formatter:TAOTAO.formatDateTime">创建日期</th>
			<th data-options="field:'updated',width:130,align:'center',formatter:TAOTAO.formatDateTime">更新日期</th>
		</tr>
	</thead>
</table>
<div id="itemEditWindow" class="easyui-window" title="编辑用户"
	data-options="modal:true,closed:true,iconCls:'fa fa-edit',href:'/rest/page/item-edit'"
	style="width: 50%; height: 50%; padding: 10px;"></div>
<script>
//调试需要加上的
//@ sourceURL=/js/customer/user-edit.js
function getSelectionsIds() {
	var userList = $("#userList");
	var sels = userList.datagrid("getSelections");
	var ids = [];
	for ( var i in sels) {
	    ids.push(sels[i].id);
	}
	ids = ids.join(",");
	return ids;
    }

function getSelectionsUserNames() {
	var userList = $("#userList");
	var sels = userList.datagrid("getSelections");
	var usernames = [];
	for ( var i in sels) {
	    usernames.push(sels[i].username);
	}
	usernames = usernames.join(",");
	return usernames;
    }
    var toolbar = [
	    {
		text : '新增',
		iconCls : 'fa fa-plus-square',
		handler : function() {
		    $(".tree-title:contains('新增商品')").parent().click();
		}
	    },
	    {
		text : '编辑',
		iconCls : 'fa fa-edit',
		handler : function() {
		    var usernames = getSelectionsUserNames();
		    if (usernames.length == 0) {
			$.messager.alert('提示', '必须选择一个用户才能编辑!');
			return;
		    }
		    if (usernames.indexOf(',') > 0) {
			$.messager.alert('提示', '只能选择一个用户!');
			return;
		    }
		    editUser(usernames);
		}
	    },
	    {
		text : '删除',
		iconCls : 'fa fa-minus-square',
		handler : function() {
		    var ids = getSelectionsIds();
		    if (ids.length == 0) {
			$.messager.alert('提示', '未选中商品!');
			return;
		    }
		    $.messager
			    .confirm(
				    '确认',
				    '确定删除ID为 ' + ids + ' 的商品吗？',
				    function(r) {
					if (r) {
					    var params = {
						"ids" : ids
					    };
					    $
						    .post(
							    "/rest/item/delete",
							    params,
							    function(data) {
								if (data.status == 200) {
								    $.messager
									    .alert(
										    '提示',
										    '删除商品成功!',
										    undefined,
										    function() {
											$(
												"#userList")
												.datagrid(
													"reload");
										    });
								}
							    });
					}
				    });
		}
	    }];
</script>